package com.atguigu.service.impl;

import cn.hutool.core.date.DateUtil;
import com.atguigu.dto.order.OrderStatisticsDto;
import com.atguigu.entity.order.OrderInfo;
import com.atguigu.entity.order.OrderStatistics;
import com.atguigu.mapper.OrderInfoMapper;
import com.atguigu.service.OrderInfoService;
import com.atguigu.vo.order.OrderStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class OrderInfoServiceImpl implements OrderInfoService {
    @Autowired
    private OrderInfoMapper orderInfoMapper;

    @Override
    public OrderStatisticsVo getOrderStatisticsData(OrderStatisticsDto orderStatisticsDto) {
        List<OrderStatistics> orderStatisticsList = orderInfoMapper.selectList(orderStatisticsDto);
        List<String> dateList = orderStatisticsList.stream()
                .map(orderStatistics -> DateUtil.format(orderStatistics.getOrderDate(), "yyyy-MM-dd"))
                .collect(Collectors.toList());

        List<BigDecimal> decimalList = orderStatisticsList.stream()
                .map(OrderStatistics::getTotalAmount)
                .collect(Collectors.toList());

        OrderStatisticsVo orderStatisticsVo = new OrderStatisticsVo();
        orderStatisticsVo.setAmountList(decimalList);
        orderStatisticsVo.setDateList(dateList);
        return orderStatisticsVo;
    }
}
